package com.example.xyr.myapplication.utils

import android.content.Context

/**
 * Created by ylcf on 2018/9/7.
 */
class MyIntent {

    private val map: HashMap<String, Any?> = HashMap()

    private constructor ()

    companion object {
        lateinit var context: Context
        fun init(context: Context) {
            this.instance
            this.context = context
        }

        val instance by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
            MyIntent()
        }
    }

    fun <T> putExtra(key: String, t: T) {
        map.put(key, t)
    }

    fun <T> getExtra(key: String, delete: Boolean): T {
        val t = map[key]
        if (delete) {
            map.remove(key)
        }
        return t as T
    }

}